package isCircularSentence;

import java.util.Arrays;
import java.util.Scanner;

public class Solution {
    public boolean isCircularSentence(String sentence) {
        int i = 0,n = sentence.length()-1;
        if(sentence.charAt(0)!=sentence.charAt(n-1))return false;
        while (i<n) {
            if(i == n-1) {
                if(sentence.charAt(i) != sentence.charAt(0)) return false;
            }
            if(sentence.charAt(i) != ' ') {
                i++;
            } else {
                if(i == n-1) {
                    if(sentence.charAt(i)!=sentence.charAt(0)) return false;
                } else {
                    if(sentence.charAt(i-1)!=sentence.charAt(i+1)) {
                        return false;
                    }
                }
                i++;
            }
        }
        return true;
    }
}
